package com.park.controller;

import com.park.bean.AttractsType;
import com.park.bean.TicketsType;
import com.park.common.CommonResult;
import com.park.service.IAttractsTypeService;
import com.park.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@CrossOrigin
public class AttractsTypeController {
    @Autowired
    IAttractsTypeService attractsTypeService;

    @GetMapping("atype")
    public CommonResult getAttractsType(AttractsType attractsType, Page page){
        List<AttractsType> res=attractsTypeService.getAttractsType(attractsType,page);
        int count=attractsTypeService.getCount(attractsType);
        HashMap map=new HashMap();
        map.put("res",res);
        map.put("count",count);
        return CommonResult.success(map);
    }

    //添加数据
    @PostMapping("atype")
    public CommonResult postAttractsType(@RequestBody AttractsType attractsType){
        int count=attractsTypeService.postAttractsType(attractsType);
        if(count>0){
            return CommonResult.success(attractsType);
        }else{
            return CommonResult.fail();
        }
    }

    @DeleteMapping("atype/{id}")
    public CommonResult delAttractsType(@PathVariable int id){
        int count= attractsTypeService.delAttractsType(id);
        if(count>0){
            return CommonResult.success();
        }else{
            return CommonResult.fail();
        }
    }

    @PutMapping("atype")
    public CommonResult editAttractsType(@RequestBody AttractsType  attractsType){
        int count=attractsTypeService.editAttractsType(attractsType);
        if(count>0){
            return CommonResult.success(attractsType);
        }else{
            return CommonResult.fail();
        }
    }
}
